import 'dart:async';
import 'package:flutter/material.dart';
import 'dart:ui';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'CommonColor.dart';

/// 二手车
///

class VOMSecondHand extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _VOMSecondHand();
  }
}

class _VOMSecondHand extends State<VOMSecondHand> {
  var screenUtil = ScreenUtil.instance;
  var _showLoadingDialog = true;
  @override
  Widget build(BuildContext context) {
    screenUtil = ScreenUtil(width: 750, height: 1334)..init(context);
    return Scaffold(
        // appBar: AppBar(
        //   title: Text("哈哈"),
        // ),
        body: getBody());
        
  }

  getBody() {
    if (_showLoadingDialog) {
      new Timer(new Duration(seconds: 2), () {
        setState(() {
          _showLoadingDialog = false;
        });
      });
      return getProgressDialog();
    } else {
      return getContainer();
    }
  }

  getProgressDialog() {
    return Center(child: CircularProgressIndicator());
  }

  Container getContainer() {
    return Container(
      // 网络请求
      // decoration: BoxDecoration(
      //   image: DecorationImage(
      //       image: NetworkImage(
      //           "https://images.unsplash.com/photo-1471115853179-bb1d604434e0?dpr=1&auto=format&fit=crop&w=767&h=583&q=80&cs=tinysrgb&crop="),
      //       fit: BoxFit.cover),
      // ),

      // 加载本地资源
      decoration: BoxDecoration(
        image: DecorationImage(
          image: new ExactAssetImage('assets/images/es8.jpg'),
          fit: BoxFit.cover,
        ),
      ),

      child: getNewColumn(),
    );
  }

  Column getNewColumn() {
    return Column(
      mainAxisAlignment: MainAxisAlignment.start,
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.start,
      verticalDirection: VerticalDirection.down,
      children: <Widget>[
        Container(
          padding: EdgeInsets.fromLTRB(25, 79, 25, 0),
          child: Text(
            "置换服务",
            style: TextStyle(
              color: Colors.white,
              fontSize: 30.0,
              fontFamily: 'Ewert',
            ),
            textAlign: TextAlign.left,
          ),
        ),
        Container(
          padding: EdgeInsets.fromLTRB(25, 5, 25, 0),
          child: Text(
            "当你购置蔚来新车，新车已交付且你的旧车已完成交易时，我们会根据你的置换单数，发放5000积分一单。（1台旧车置换1台蔚来新车，视为一单）",
            style: TextStyle(
              color: Colors.white,
              fontSize: 14.0,
              fontFamily: 'Ewert',
            ),
            textAlign: TextAlign.left,
          ),
        ),
        Container(
          margin: EdgeInsets.fromLTRB(20, 300, 20, 20),
          height: 250.0,
          width: 400,
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.all(Radius.circular(5.0)),
          ),
          child: getCardView(),
        ),
      ],
    );
  }

  Widget getCardView() {
    return Column(
      mainAxisSize: MainAxisSize.max,
      crossAxisAlignment: CrossAxisAlignment.start,
      children: <Widget>[
        Padding(
          padding: EdgeInsets.fromLTRB(20, 20, 20, 0),
          child: Container(
            child: Text(
              "爱车置换流程",
              style: TextStyle(
                color: Color.fromRGBO(54, 60, 84, 1),
                fontSize: 20.0,
                fontFamily: 'Ewert',
              ),
              textAlign: TextAlign.left,
            ),
          ),
        ),
        SizedBox(
          height: 10,
          child: Text(
            "",
            style: TextStyle(
              color: Colors.black,
            ),
          ),
        ),
        Container(
          margin: EdgeInsets.fromLTRB(20, 10, 20, 0),
          color: Color.fromRGBO(240, 241, 242, 1),
          height: 1,
        ),
        Container(
          padding: EdgeInsets.fromLTRB(10, 15, 10, 0),
          child: buttonSection(),
        ),

        // Container(
        //   margin: EdgeInsets.fromLTRB(20, 34, 20, 0),
        //   height: 45.0,
        //   width: 400,
        //   decoration: BoxDecoration(
        //     borderRadius: BorderRadius.all(Radius.circular(23.0)),
        //     color: Color.fromRGBO(0, 190, 190, 1),
        //   ),
        //   child: Padding(
        //         padding: EdgeInsets.fromLTRB(0, 10, 0, 0),
        //         child: Text(
        //           "立即置换",
        //           style: TextStyle(
        //             color: Colors.white,
        //             fontSize: 20.0,
        //             fontFamily: 'Ewert',
        //           ),
        //           textAlign: TextAlign.center,
        //         ),
        //       ),
        // ),

        Container(
          margin: EdgeInsets.fromLTRB(20, 34, 20, 0),
          height: 45.0,
          width: 400,
          child: FlatButton(
            color: CommonColor.cor0190190,
            highlightColor: CommonColor.cor0190190,
            colorBrightness: Brightness.dark,
            splashColor: Colors.grey,
            child: Text("立即置换"),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(22.5)),
            onPressed: () => {
              
              Navigator.pushNamed(context, "submitApplication")

            },
          ),
        ),
      ],
    );
  }

  /// 流程控件
  Widget buttonSection() {
    return new Container(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          buildButtonColumn("提交申请-完成", '提交申请'),
          buildProcessContainer(false),
          buildButtonColumn("上门检测", '免费上门检测'),
          buildProcessContainer(false),
          buildButtonColumn("用户竞价", '卖家竞争'),
          buildProcessContainer(false),
          buildButtonColumn("交易成功", '交易成功'),
        ],
      ),
    );
  }

  /// 流程button
  Column buildButtonColumn(String icon, String label) {
    // Color color = Theme.of(context).primaryColor;
    Color color = Color.fromRGBO(54, 60, 84, 1);
    return new Column(
      mainAxisSize: MainAxisSize.min,
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // new Icon(icon, color: color),
        new Image.asset(
          "assets/images/${icon}.png",
          fit: BoxFit.cover,
        ),
        new Container(
          margin: const EdgeInsets.only(top: 8.0),
          child: new Text(
            label,
            style: new TextStyle(
              fontSize: 12.0,
              fontWeight: FontWeight.w400,
              color: color,
            ),
          ),
        ),
      ],
    );
  }

  Container buildProcessContainer(bool finish) {
    String imageStr = finish ? "未进行" : "已完成";
    return Container(
      padding: const EdgeInsets.only(top: 0.0),
      child: Image.asset("assets/images/${imageStr}.png", fit: BoxFit.contain),
    );
  }
}

// Container(
//           margin: EdgeInsets.fromLTRB(20, 34, 20, 0),
//           height: 45.0,
//           width: 400,
//           decoration: BoxDecoration(
//             borderRadius: BorderRadius.circular(23.0),

//           ),
//           child: new RaisedButton(
//             child: const Text('立即置换'),
//             clipBehavior: Clip,
//             color: CommonColor.cor0190190,
//             textColor: Colors.white,
//             elevation: 4.0,
//             animationDuration: Duration(),
//             splashColor: CommonColor.cor0190190,
//             onPressed: () {

//             },
//           ),
//         ),
